package com.nhutcm.trackingthief.utils;

import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;

import android.util.Log;

public class RootUtils {

	public static final String TAG = "com.nhutcm.trackingthief.utils.RootUtils";

	public static void deleteRootFile(String filePath) {
		Process p;
		try {
			p = Runtime.getRuntime().exec("su");

			String command = "rm " + filePath;

			DataOutputStream os = new DataOutputStream(p.getOutputStream());
			os.writeBytes(command + "\n");
			os.writeBytes("exit\n");
			os.flush();
			try {
				p.waitFor();
				if (p.exitValue() != 255) {
					Log.i(TAG, "Root permission");
				} else {
					Log.i(TAG, "NOT-Root permission");
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
		
	public static void deleteIfExist(String filePath) {
		File f = new File(filePath);
		if (f.exists() && f.isFile()) {
			deleteRootFile(filePath);
		}
	}

}
